﻿#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MCMLXVII.Client.Common.Session;
using MCMLXVII.BackEnd.Services.SystemConfiguration.Messages;
using MCMLXVII.BackEnd.Services.Common.Messages;
using MCMLXVII.BackEnd.Services.OrganizationChart.Interfaces;
using MCMLXVII.BackEnd.Services.OrganizationChart.Messages;

#endregion

namespace MCMLXVII.Tools.OrganizationChart
{
    partial class frmAddPermission : Form
    {
        private int _MemberID;
        public int MemberID
        {
            get
            {
                return _MemberID;
            }
        }

        private string _MemberName;
        public string MemberName
        {
            get
            {
                return _MemberName;
            }
        }

        private bool _FullControl;
        public bool FullControl
        {
            get
            {
                return _FullControl;
            }
        }

        private bool _Read;
        public bool Read
        {
            get
            {
                return _Read;
            }
        }

        private bool _Create;
        public bool Create
        {
            get
            {
                return _Create;
            }
        }

        private bool _Update;
        public bool UpdateData
        {
            get
            {
                return _Update;
            }
        }

        private bool _Delete;
        public bool Delete
        {
            get
            {
                return _Delete;
            }
        }

        private bool _NoAccess;
        public bool NoAccess
        {
            get
            {
                return _NoAccess;
            }
        }

        private bool _ManageSecurity;
        public bool ManageSecurity
        {
            get
            {
                return _ManageSecurity;
            }
        }

        private bool _Audit;
        public bool Audit
        {
            get
            {
                return _Audit;
            }
        }


        public frmAddPermission()
        {
            InitializeComponent();
            btnFind.Enabled = true;
            lstUsers.Enabled = true;
            txtFilter.Enabled = true;
        }
        public frmAddPermission(int MemberID, string MemberName, bool FullControl, bool Read, bool Create, bool Update, bool Delete, bool NoAccess, bool ManageSecurity, bool Audit)
        {

            _MemberID = MemberID;
            _MemberName = MemberName;

            InitializeComponent();
            lstUsers.Enabled = false;
            txtFilter.Enabled = false;
            btnFind.Enabled = false;
            string s = "00000" + _MemberID.ToString();
            txtFilter.Text = s.Substring(s.Length - 5) + " - " + _MemberName;
            chkAudit.Checked = Audit;
            chkCreate.Checked = Create;
            chkDelete.Checked = Delete;
            chkFullControl.Checked = FullControl;
            chkRead.Checked = Read;
            chkSecurity.Checked = ManageSecurity;
            chkUpdate.Checked = Update;
        }

        private void frmAddPermission_Load(object sender, EventArgs e)
        {

        }

        private void chkFullControl_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
                chkNoAccess.Checked = false;
        }

        private void chkRead_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
                chkNoAccess.Checked = false;
        }

        private void chkCreate_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
                chkNoAccess.Checked = false;
        }

        private void chkDelete_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
                chkNoAccess.Checked = false;
        }

        private void chkUpdate_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
                chkNoAccess.Checked = false;
        }

        private void chkNoAccess_CheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
            {
                chkFullControl.Checked = false;
                chkRead.Checked = false;
                chkCreate.Checked = false;
                chkUpdate.Checked = false;
                chkDelete.Checked = false;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstUsers.SelectedIndex > -1)
            { 
                string s  = (string)lstUsers.Items[lstUsers.SelectedIndex];
                _MemberID = System.Int32.Parse(s.Substring(0, 5));
                _MemberName = s.Substring(6);
                this.DialogResult = DialogResult.OK;
                _Audit = chkAudit.Checked;
                _Create = chkCreate.Checked;
                _Delete = chkDelete.Checked;
                _FullControl = chkFullControl.Checked;
                _ManageSecurity = chkSecurity.Checked;
                _NoAccess = chkNoAccess.Checked;
                _Read = chkRead.Checked;
                _Update = chkUpdate.Checked;
                this.Close();
            }
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            lstUsers.Items.Clear();
            msgBasicOrganizationMemberInfo[] inf = BusinessActions.FindorganizationMembersByDescription(txtFilter.Text);
            if (inf != null)
            {
                foreach (msgBasicOrganizationMemberInfo x in inf)
                { 
                    string s = "00000"+x.ID.ToString();
                    lstUsers.Items.Add(s.Substring(s.Length - 5) + "-" + x.Description);
                }

            }
        }

        private void lstUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
    }
}